package com.delistry.server.model;

import java.util.HashMap;
import java.util.Map;

import com.delistry.server.GeneralThreadPool;
import com.delistry.server.clientpacket.ClientPacket;
import com.delistry.server.clientpacket.ClientPacketProcess;
import com.delistry.server.clientpacket.LoginPacketProcess;

public class DeliverManager {
	private static DeliverManager _instance;

	private DeliverManager() {
		InitialPacketProcess();
	}

	public static DeliverManager getInstance() {
		if (_instance == null) {
			_instance = new DeliverManager();
		}
		return _instance;
	}
	
	
	private Map<Integer, ClientPacketProcess> packetProcessMaps;

	private void InitialPacketProcess() {
		//Initial Maps
		packetProcessMaps = new HashMap<Integer, ClientPacketProcess>();
		
		//Initial All Packet Process
		LoginPacketProcess loginPacketProcess = new LoginPacketProcess();
		
		//Put All Packet Process
		packetProcessMaps.put(loginPacketProcess.getOP(), loginPacketProcess);
		
		//Execute All Packet Process
		for(ClientPacketProcess cpp : packetProcessMaps.values()){
			GeneralThreadPool.getInstance().execute(cpp);
		}
	}

	//
	public void HandlePacket(int op, ClientPacket clientPacket) {
		ClientPacketProcess packetProcess = packetProcessMaps.get(op);
		if(packetProcess == null)
			return;
		packetProcess.AddClientPacket(clientPacket);
	}

	/**
	 * 廣播相關
	 */
	public void broadcastPacketToAllClient(String packet) {

	}

}